
attribute vec4 vPos; 
attribute vec3 vNormal; 
attribute vec2 vTexCoord; 
attribute vec3 vTangent;
varying vec2 texcoord;
varying vec3 tnorm;
varying vec3 lvec;
varying vec3 hvec;
uniform mat4 mvMatrix;
uniform mat4 mvpMatrix;
uniform mat3 normalMatrix;
uniform vec4 lightPos;
void transp3 (inout mat3 m)
{
  float temp;
  temp = m[0][1];
  m[0][1] = m[1][0];
  m[1][0] = temp;
  temp=m[0][2];
  m[0][2] = m[2][0];
  m[2][0] = temp;
  temp=m[1][2];
  m[1][2] = m[2][1];
  m[2][1] = temp;
}
void main (void) 
{ 
  vec4 ep = mvMatrix * vPos;
  lvec = vec3(normalize(lightPos - ep));
  vec3 v = normalize(vec3(-ep));
  hvec = normalize(lvec + v);
  vec3 norm = normalize(normalMatrix * vNormal);
  vec3 tang = normalize(normalMatrix * vTangent);
  vec3 binorm = cross(norm,tang);
  mat3 rot = mat3(tang,binorm,norm);
  transp3(rot);
  lvec = rot*lvec;
  hvec = rot*hvec;
  texcoord=vTexCoord;
  gl_Position = mvpMatrix * vPos;
}

